<?php
/**
 * Created by PhpStorm.
 * User: david
 * Date: 2018/5/29
 * Time: 23:12
 */

namespace app\admin\controller;


use app\admin\Controller;
use traits\controller\Jump;
use app\common\model\Menu as MenuModel;
use app\common\model\Buju as BujuModel;

class Buju extends Controller
{
    use \app\admin\traits\controller\Controller;
    use Jump;

    public function add()
    {
        if ($this->request->isAjax()) {
            $data = $this->request->except('id');
            BujuModel::create($data);
            return ajax_return_adv('添加成功');
        } else {
            $menus = MenuModel::getMenusByPid(3);
            $this->view->assign('menus', $menus);
            return $this->view->fetch('edit');
        }
    }

    public function edit($id)
    {
        if ($this->request->isAjax()) {
            $id = $this->request->param('id');
            $data = $this->request->except(['id']);
            BujuModel::where('id', $id)->update($data);
            return ajax_return_adv('修改成功');
        } else {
            $buju = BujuModel::get($id);
            $menus = MenuModel::getMenusByPid(3);
            $this->view->assign('menus', $menus);
            $this->view->assign('buju', $buju);
            return $this->view->fetch('edit');
        }
    }
}